package com.sunther.document.util;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.jwt.JWT;

import javax.servlet.http.HttpServletRequest;

/**
 * @author csb
 * @description: TODO
 * @date 2023/5/30 11:24
 */
public class UserInfoUtil {

    public static Integer getRoleId(HttpServletRequest request) {
        String token =  request.getHeader("Authorization");
        Integer roleId = Integer.valueOf(ObjectUtil.toString(JWT.of(token).getPayload("roleId")));
        return roleId;
    }

    public static Integer getUserId(HttpServletRequest request) {
        String token =  request.getHeader("Authorization");
        Integer userId = Integer.valueOf(ObjectUtil.toString(JWT.of(token).getPayload("userId")));
        return userId;
    }

    public static String getProjectId(HttpServletRequest request) {
        String token =  request.getHeader("Authorization");
        String projectId = ObjectUtil.toString(JWT.of(token).getPayload("projectId"));
        return projectId;
    }

    public static String getName(HttpServletRequest request) {
        String token =  request.getHeader("Authorization");
        String name = ObjectUtil.toString(JWT.of(token).getPayload("name"));
        return name;
    }

    public static String getNickName(HttpServletRequest request) {
        String token =  request.getHeader("Authorization");
        String nickName = ObjectUtil.toString(JWT.of(token).getPayload("nickName"));
        return nickName;
    }
}
